﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Iit.ITBI.MDSManager.Microsoft.MasterDataServices;

namespace Iit.ITBI.MDSManager
{
    class CustomModel : CustomObject
    {

        public Identifier VersionID
        {
            get;
            set;
        }

        public CustomModel(string Name, Guid MUID) :base(Name,MUID)
        {
            
        }

        public CustomModel(DataRow MasterToSlaveMappingData, SlaveOrMaster ModelType, MDSQueryVersion QueryVersion)
        {
            if (QueryVersion == MDSQueryVersion.GetMasterToSlaveMappingV1)
            {
                switch (ModelType)
                {
                    case SlaveOrMaster.Master:
                        base.Name = MasterToSlaveMappingData["MasterModel_Name"].ToString();
                        base.MUID = (Guid)MasterToSlaveMappingData["MasterModel_MUID"];
                        break;

                    case SlaveOrMaster.Slave:
                        base.Name = MasterToSlaveMappingData["SlaveModel_Name"].ToString();
                        base.MUID = (Guid)MasterToSlaveMappingData["SlaveModel_MUID"];
                        break;
                }
                
                base.Initialize();

            }
            else
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Query Version {0} is not supported.", QueryVersion.ToString());
                throw new NotSupportedException(msg.ToString());
            }
        }

        public override string ToString()
        {
            StringBuilder str = new StringBuilder();

            str.Append("Model: " + base.ToString());

            return str.ToString();
        }
        
    }
}
